package tv.youxing.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import tv.youxing.android.R;
import tv.youxing.android.entity.MyCollectionModel;
import tv.youxing.android.utils.PicassoUtils;
import tv.youxing.android.utils.ShareUtils;

/**
 * Created by Administrator on 2017/6/26.
 */

public class MyFabulousAdapter extends BaseAdapter {
    private Context context;
    private List<MyCollectionModel.ResultBean.DataBean> listData = new ArrayList<>();
    private LayoutInflater layoutInflater;


    public MyFabulousAdapter(Context context, List<MyCollectionModel.ResultBean.DataBean> listData) {
        this.context = context;
        this.listData = listData;
        layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return listData==null || listData.size()==0 ? 0 : listData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        if (viewHolder==null) {
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.mycollection_item, null);
            viewHolder.ivIcon = (ImageView) convertView.findViewById(R.id.ivIcon);
            viewHolder.tvTitle = (TextView) convertView.findViewById(R.id.title);
            viewHolder.tvPlayCount = (TextView) convertView.findViewById(R.id.play_count);
            viewHolder.tvCommentCount = (TextView) convertView.findViewById(R.id.comment_count);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        int width = ShareUtils.getInt(context,"width",100);
        PicassoUtils.loadImageViewSize(context, listData.get(position).getCover(),(width-6)/2,(width-6)/2, R.drawable.logo,viewHolder.ivIcon);
        viewHolder.tvTitle.setText(listData.get(position).getAlbum_name());
        viewHolder.tvTitle.setLines(1);
        viewHolder.tvPlayCount.setText(listData.get(position).getPlay_count()+"播放");
        viewHolder.tvCommentCount.setText(listData.get(position).getComment_count().toString()+"评论");



        return convertView;
    }


    class ViewHolder{
        private ImageView ivIcon;
        private TextView tvTitle;
        private TextView tvPlayCount;
        private TextView tvCommentCount;
    }
}
